﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WcfServiceBomberman.Interfaces;
using WcfServiceBomberman.MatchMaking;
using BomberManServer.Utils;
using WcfServiceBomberman.Databases;

namespace WcfServiceBomberman
{
    public class Context
    {
        protected static Context instance = null;

        public ServiceWebSite website;
        public ServiceGameServer server;
        public MatchMaker matchmaker { get; protected set; }
        public Database database { get; protected set; }
        public Random randomizer { get; protected set; }
        
        // player or team in ranked queue
        public ConcurrentDoubleBufferedLinkedList<Queueable> players { get; protected set; }

        private Context()
        {
            players = new ConcurrentDoubleBufferedLinkedList<Queueable>();
            instance = this;
            randomizer = new Random();
            matchmaker = new MatchMaker();
            database = Database.load("database.bin");
            (new System.Threading.Thread(matchmaker.start)).Start();
        }

        public class Handler
        {
            protected Handler() { if (instance == null) new Context(); }
            protected Context context { get { return Context.instance; } }
        }
    }
}
